#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time       :   20:40
# Author     : Y4
# Site       : 
# File       : 05 面向对象-对象之间的调用.py
# Software   : PyCharm
import random


class Road:
    def __init__(self, name, len):
        self.name = name
        self.len = len


class Car:
    def __init__(self, brand, speed):
        self.brand = brand
        self.speed = speed

    def __str__(self):
        return '{}品牌的车,速度是{}'.format(self.brand, self.speed)

    def get_time(self, road):
        ran_time = random.randint(1, 10)
        msg = '{}品牌的车,在{}公路上,已{}速度,行驶了{}小时.'.format(self.brand, road.name, self.speed, ran_time)
        print(msg)


road = Road('绕城公路', 20000)
car = Car('奥迪', 120)
print(car)                  # 奥迪品牌的车,速度是120     __str__ 方法

car.get_time(road)


